﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using model;
using Bll;

public partial class Sedit : System.Web.UI.Page
{
    StudentBll bll = new StudentBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtSbirth.Attributes.Add("onfocus","javascript:show()");
        if (!IsPostBack)
        {
            string ssno = Session["userid"].ToString();
            try
            {
                Student student = bll.GetSingle(ssno);
                this.txtSno.Text = student.Sno;
                this.txtSname.Text = student.Sname;
                this.txtSsex.Text = student.Ssex;
                this.txtSmajor.Text = student.Smajor;
                this.txtSclass.Text = student.Sclass;
                this.txtSbirth.Text = student.Sbirth.Year.ToString()+"-"+student.Sbirth.Month.ToString()+"-"+student.Sbirth.Day.ToString();
                //this.txtSgo.Text = student.Go;
                Calendar1.TodaysDate = student.Sbirth;
            }
            catch (Exception ex)
            {
                string js = "<script>alert('"+ex.Message+"');</script>";
                Response.Write(js);
            }   
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            Student student = new Student();
            student.Sno = txtSno.Text;
            student.Sname = txtSname.Text;
            student.Ssex = txtSsex.Text;
            student.Smajor = txtSmajor.Text;
            student.Sclass = txtSclass.Text;
            //student.Go = txtSgo.Text;
            student.Sbirth = Convert.ToDateTime(txtSbirth.Text);
            bll.Update(student);
            Response.Write("<script>alert('修改成功！');location.href('Default.aspx');</script>");
        }
        catch (Exception ex)
        {
            string js = "<script>alert('" + ex.Message + "');</script>";
            Response.Write(js);
        }
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        txtSbirth.Text = Calendar1.SelectedDate.ToLongDateString();
        Calendar1.Attributes.Add("onblur", "javascript:document.getElementById('Calendar1').style.display=\"none\";");
    }
    protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
    {
        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "key", "document.getElementById('ca').style.display=\"block\";", true);
    }
}